# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

_luaversions="5.1 5.2 5.3 5.4"

pkgname=lua-pc
_name=lpc
pkgver=1.0.0
pkgrel=12
pkgdesc="Lua Process Call"
url="https://github.com/LuaDist/lpc"
arch="all"
license="MIT"
depends="lua5.1-pc"
source="https://dev.alpinelinux.org/archive/lpc/lpc-$pkgver.tar.gz
	lpc-lua5.2-compat.patch
	"

for _i in $_luaversions; do
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-pc:_pc_${_i/./_}"
done

builddir="$srcdir/$_name-$pkgver"
options="!check"

prepare() {
	default_prepare
	for _i in $_luaversions; do
		cp -r "$builddir" "$srcdir"/build-$_i
	done
}

build() {
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		make LUA_PKGCONF="lua$_i" \
			CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS -shared"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_split_pc() {
	local _ver=$1
	pkgdesc="$pkgdesc for Lua $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=""

	mkdir -p "$subpkgdir"
	cd "$srcdir"/build-$_ver
	make install LUA_PKGCONF="lua$_ver" DESTDIR="$subpkgdir"
}

for _i in $_luaversions; do
	eval "_pc_${_i/./_}() { _split_pc $_i; }"
done

sha512sums="a955f802b9ea7c4615b8b22b1f4ab540d41e4ddb0edb5e1b77f2f2e1472c49248cb276f8bfec6b929d23ef01681a0018db6cbd401ade1cc1eb366b0a6ace9772  lpc-1.0.0.tar.gz
d98aba2a757cb4dd6ceebefb4b0bebb4b91d8a38360193f6246be727f0dc89fe438154596c22232d16539f86d5589730e13834cdaf5b71965728904fbdea8615  lpc-lua5.2-compat.patch"
